package agent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import processing.core.PVector;

public class Agent {
	Main p;
	int[] colors; //an agent may want more than one color
	
	//about colors:
	//in processing colors are 32bit integers of the form AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB
	//we will be working in the HSBA space by default,
	//so use the hue(), saturation(), brightness(), and alpha() functions to extract those values from the integer
	//to create an HSBA color, just use int myColor = p.color(H, S, B, A)
	//where H,S,B, and A are integers between 0 and 255 or floats between 0 and 1.0
	
	List<PVector> position; //current position = position[0]
	List<PVector> velocity; //current velocity = velocity[0]
	HashMap<String,Double> traits; //this is where you put parameters specific to your agent
	ArrayList<Behavior> behaviors;
	
	Agent(Main p) {
		this.p = p;
		behaviors = new ArrayList<Behavior>();
		traits = new HashMap<String,Double>();
		//THINGS YOU MUST DO:
		//Initialize position, velocity, and colors arrays
	}
	
	public void draw() {
		for (int i = 0; i < behaviors.size(); i++) {
			behaviors.get(i).apply(this);
		}
		//if you want the agent to do things that can't be changed, put them here
	}
	
	public int getColor() {
		return colors[0];
	} //the "main" color of the agent should be the first in the array
	
	public void setColor(int c) {
		colors[0] = c;
	}
	
	public int[] getColors() {
		return colors;
	}
	
	public void setColor(int idx, int c) {
		colors[idx] = c;
	}
	public void addPosition(PVector p){
		position.add(0,p);
	}
	public void addVelocity(PVector p){
		velocity.add(0,p);
	}
	public PVector[] getPositions() {
		return position.toArray(new PVector[0]);
	} //returns current and previous positions
	
	public PVector getCurrentPosition() {
		return position.get(0);
	} //only returns current position
	
	public PVector[] getVelocities() {
		return velocity.toArray(new PVector[0]);
	} //returns current and previous velocities
	
	public PVector getCurrentVelocity() {
		return velocity.get(0);
	} //only returns current velocity
	
	public void setPosition(PVector p) {
		position.get(0).set(p);
	} //don't be a dick with this one
	
	public void setVelocity(PVector v) {
		velocity.get(0).set(v);
	}
	
	public void setPosition(int idx, PVector p) {
		position.get(idx).set(p);
	}
	
	public void setVelocity(int idx, PVector v) {
		velocity.get(idx).set(v);
	}
	
	public void addTrait(String s, double d) {
		traits.put(s, d);
	} //inject parameters into agents with this method or change existing parameters
	
	public void removeTrait(String s) {
		traits.remove(s);
	} //you have the option to remove the parameters you previously injected
	
	public HashMap<String, Double> getTraits() {
		return traits;
	} //you can also treat auxiliaries as random parameters; if you don't care about which one you change, pick one from the list
	
	public double getTrait(String s){
		return traits.get(s).doubleValue();
	} //read the parameters you previously injected
	
	public void addBehavior(Behavior b) {
		behaviors.add(b);
	} //inject behaviors into the agent with this method
	
	public void removeBehavior(Behavior b) {
		behaviors.remove(b);
	}
	
	public void setBehavior(int idx, Behavior b) {
		behaviors.set(idx, b);
	}
	
	public ArrayList<Behavior> getBehaviors() {
		return behaviors;
	}
}
